//
//  StatusDetailDock.m
//  SinaWeibo
//
//  Created by mj on 13-8-29.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import "StatusDetailDock.h"
#import "UIButtonExtend.h"
#import "AyDefine.h"
#import "UIImageExtend.h"
@implementation StatusDetailDock

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)setFrame:(CGRect)frame
{
    frame.size.width = [UIScreen mainScreen].bounds.size.width;
    frame.size.height = 44;
    [super setFrame:frame];
    if (self.subviews.count || frame.size.width == 0) return;
    
    // 3个按钮
    [self addBtnWithTitle:@"转发" icon:@"statusdetail_icon_retweet2.png" action:@selector(repost) index:0];
    [self addBtnWithTitle:@"评论" icon:@"statusdetail_icon_comment2.png" action:@selector(comment) index:1];
    [self addBtnWithTitle:@"赞" icon:@"statusdetail_icon_like2.png" action:@selector(attitude) index:2];
}

#pragma mark 添加按钮
- (void)addBtnWithTitle:(NSString *)title icon:(NSString *)icon action:(SEL)action index:(int)index
{
    CGFloat middleMargin = 10;
    CGFloat leftMargin = 5;
    CGFloat btnWidth = (self.frame.size.width - 2 * (middleMargin + leftMargin))/3;
    CGFloat btnHeight = 35;
    CGRect btnBounds = (CGRect){CGPointZero, {btnWidth, btnHeight}};
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    //[btn setAllStateBackgound:@"toolbar_button.png"];
    
//    [btn setTitle:title forState:UIControlStateNormal];
//    btn.titleLabel.font = [UIFont systemFontOfSize:13];
//    btn.titleEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0);
//    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [btn setImage:[UIImage imageNamed:icon] forState:UIControlStateNormal];
    CGFloat centerX = leftMargin + btnWidth * 0.5 + index * (btnWidth + middleMargin);
    CGFloat centerY = self.frame.size.height * 0.5;
    btn.center = CGPointMake(centerX, centerY);
    [btn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    btn.bounds = btnBounds;
    [self addSubview:btn];
}

#pragma mark 转发
- (void)repost
{
    
}

#pragma mark 评论
- (void)comment
{
    
}

#pragma mark 赞
- (void)attitude
{
    
}

@end
